package com.cjq.allservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cjq.allservice.entity.*;
import com.cjq.allservice.service.*;
import com.cjq.utils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cjq
 * @since 2022-03-24
 */
@RestController
@RequestMapping("/allservice/standing-book")
@CrossOrigin
public class StandingBookController {

    private final StandingBookService standingBookService;

    private final GoodsService goodsService;

    private final UserService userService;

    private final OrdersService ordersService;

    private final BrandService brandService;

    public StandingBookController(StandingBookService standingBookService,
                                  GoodsService goodsService,
                                  UserService userService,
                                  OrdersService ordersService,
                                  BrandService brandService){
        this.standingBookService=standingBookService;
        this.goodsService=goodsService;
        this.userService=userService;
        this.ordersService=ordersService;
        this.brandService=brandService;
    }


    @ApiOperation("获取台账要渲染的数据，商品售出数目，获得收益等数据")
    @GetMapping("/getAllStandingBook")
    public R getAllStandingBook(){
        QueryWrapper<StandingBook> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("sell_number");
        List<StandingBook> list = standingBookService.list(wrapper);
        List a=new ArrayList();
        List b=new ArrayList();
        List<StandingBook> list1=new ArrayList<>();

        int i=0;
        for(StandingBook standingBook:list){
            if (i>5){
                break;
            }
            i++;
            a.add(standingBook.getGoodsName());
            b.add(standingBook.getSellNumber());
            list1.add(standingBook);
        }

        List<User> userList = userService.list();
        int userNumber = userList.size();

        List<Goods> goodsList = goodsService.list();
        int goodsNumber = goodsList.size();

        List<Orders> ordersList = ordersService.list();
        int orderNumber = ordersList.size();

        List<Brand> brandList = brandService.list();
        int brandNumber = brandList.size();



        return R.succ().data("a",a)
                .data("b",b)
                .data("standingBookList",list1)
                .data("userNumber",userNumber)
                .data("goodsNumber",goodsNumber)
                .data("orderNumber",orderNumber)
                .data("brandNumber",brandNumber);
    }

}

